<?php if (!defined('THINK_PATH')) exit();?>	<!DOCTYPE html>
	<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>新疆车管家后台</title>
		<link rel="stylesheet" href="/Public/layui/css/layui.css">
		<style type="text/css">
			body{margin: 10px;}
				.demo-carousel{height: 200px; line-height: 200px; text-align: center;
			}
			#tree{
				width:300px; padding:20px;
			}
			#tree li i{
				color:#1E9FFF;
			}

		</style>
	</head>
	<body>
		 <blockquote class="layui-elem-quote">
			<div class="layui-inline">
				<label class="layui-form-label">搜索名称</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" placeholder="搜索名称" id="like">
				</div>
				<button class="layui-btn layui-input-inline" onclick="search()">搜索</button>
			</div>
		</blockquote>
		<fieldset class="layui-elem-fied site-demo-button">
			<legend>用户信息列表</legend>
			<table id="demo" lay-filter="demo"></table>
		</fieldset>

		<script src="/Public/layui/layui.all.js"></script>
		<script type="text/javascript"> 
			var like = "";
			var add_window=0;
			var edit_window=0;
			var table = layui.table;
			table.render({
				elem: '#demo',
				url:"/Admin/User/get_all_user_list",
				height: 500,
				width:1550,
				cellMinWidth:80,
				page:true,
				limit:10,
				loading:true,
				text: {    
					none: '暂无相关数据' //自定义文本，如空数据时的异常提示等默认：无数据。
				},
				cols: [[ //表头参数
					{field:'id', title:'ID', width: 80},
					{field:'openid', width:240, title: 'openid'},
					{field:'nickname', width:100, title: '微信名称'},
					{field:'sex', width:100, title: '性别',templet:function(data){
						if(data.sex==1){
							return "男";
						}else{
							return "女";
						}
					}},
					{field:'province', width:100, title: '地区'},
					{field:'city', width:100, title: '城市'},
					{field:'avatarUrl', width:100, title: '微信头像',templet:function(data){
						return '<img src="'+data.avatarurl+'" width:30px;height:30px;>'
					}},
					{field:'logo_time', width:220, title: '首次登陆时间'},
					{field:'last_time', width:220, title: '最后登陆时间'},
					{field:'logo_sum', width:100, title: '登陆次数'},
					{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'} //设置表头的删改查
				]],
				response: {				//用于对返回的数据格式的自定义
					statusName:'code', //数据状态的字段名称，默认：code
					statusCode:200,	   //成功的状态码，默认：0
					countName:'total', //数据总数的字段名称，默认：count
					dataName:'data'   //数据列表的字段名称，默认：data
				},
			});

			//所有渲染方式渲染表格重载 这里的表格重载是指对表格重新进行渲染，包括数据请求和基础参数的读取(多用于搜索)
			function search(){
				like = $('#like').val();
				//执行重载 重载默认执行当前控制器index方法
				table.reload('demo', {
					where: {  
						like: like  //设定异步数据接口的额外参数
					},
					page: {
						curr: 1 //重新从第 1 页开始
					}
			  });

			}

		//添加管理员提交
		form.on('submit(insert)', function(data){
			ajax('/Admin/Admin/question_insert',data.field,function(ret){
				layer.msg('添加成功！');
				layer.close(add_window);
				location.href="/Admin/Admin/index";
			})
			return false;
		});

		//编辑管理员提交
		form.on('submit(edit)', function(data){
			ajax('/Admin/Admin/question_edit',data.field,function(ret){
				layer.msg('编辑成功！');
				layer.close(edit_window);
				location.href="/Admin/Admin/index";
			})
			return false;
		});

		//点击编辑按钮
		table.on('tool(demo)', function(obj){ 
			if (obj.event == "edit") {
				$('#id').val(obj.data.id);
				$('#editmobile').val(obj.data.mobile);
				$('#editpwd').val(obj.data.pwd);
				edit_window=layer.open({
					type:1,
					content:$('#edituser'),
					area: ['500px', '300px']

				});
			}

			if (obj.event == "del") {
				var index = layer.confirm('删除后无法恢复，确认删除?', {
					icon: 3, 
					title:'温馨提示'
				}, function(index){
					ajax('/Admin/Admin/question_del',{
						"id":obj.data.id
					},function(res){
						obj.del();  //删除对应行（tr）的DOM结构
						layer.close(index);
						layer.msg(res.msg);
					})
					
				});
			}
			console.log(obj);
		});

		</script>
		<script type="text/html" id="barDemo">
			<div class="layui-btn-group">
				<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>
			</div>
		</script>
	</body>
	</html>\